package com.inspur.mr.parelectric;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class ElectricPartitionReducer  extends Reducer<Text, Text, Text, Text>{

	@Override
	protected void reduce(Text key, Iterable<Text> values, Context context)
			throws IOException, InterruptedException {
		double cf = 0;
		double xyf = 0;
		double kt = 0;
		double sum = 0;
		for(Text tx:values) {
			String[] t = tx.toString().split("\t");
			cf += Double.parseDouble(t[0]);
			xyf += Double.parseDouble(t[1]);
			kt += Double.parseDouble(t[2]);
		}
		sum = cf + xyf + kt;
		String result = cf + "\t" +xyf + "\t" + kt + "\t" + sum;
		context.write(key, new Text(result));
	}
}